var app = getApp()
var verify = require('../../../utils/verify-token.js')
Page({

  /**
   * 页面的初始数据
   */
  data: {
	FList:[],
    page:0,
    totalPage:0,
    loaded:false,
    loading:false,
    nolist:true,
    inputShowed: true,
    filterValue:'',
    inputVal:''
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {   
    var that = this;
    this.setData({
      sh: app.globalData.screenHeight,
      sw: app.globalData.screenWidth
    })
    
  },
  faultList:function(){		
  	var thm = this;
		var dat = {
		filter:'identifier',
		filterValue:thm.data.filterValue,		
		size:10,
		page:thm.data.page
	};		
  	wx.request({
  	  url: app.globalData.baseUrl+'device_fault2',
  	  method: 'get',
  	  header:{
  	    'AUTHORIZATION':app.globalData.token
  	  },
	  data:dat,
  	  success: function (res) {		  
        if (res.data.code == 60006) {
          verify.clearAll()
        } else if(res.data.code==200){
          var listdata = res.data.data.content;
          var listD = thm.data.FList;
          var ldh = listD.length;
          for(var i=0;i<listdata.length;i++){
            listD[ldh+i] = listdata[i]
          }
          thm.setData({
            FList:listD,
            totalPage:res.data.data.totalPages,
            loading:res.data.data.last?false:true,
            loaded:res.data.data.last?true:false
          })
  	     
        } else {
          wx.showModal({
            title: '操作失败',
            content: res.data.message,
          })
        }
  	  }
  	})
  },

	detail: function (ev) {	
	   wx.navigateTo({
		 url: 'fault-detail/fault-detail?data='+ev.currentTarget.id,
	   })
	},
	
	showInput: function () {		
		this.setData({
		  inputShowed: true
		});
	},
	  // 取消搜索
	hideInput: function () {
		this.setData({
		  inputShowed: false,
		  filterValue:'',
		  inputVal:''
		});
		this.search();
	},
	inputTyping:function(e){
		this.setData({
		  filterValue: e.detail.value
		});
		this.search();
	},
	
 
// 搜索框输入
  input: function (res) {
    this.setData({
      filterValue: res.detail.value
    })
  },
  // 查询故障
  search: function () {
    var filterValue = this.data.filterValue;    
    this.setData({
      filterValue: filterValue ,
	  FList:[],
	  page:0,
	  totalPage:0,
    })
    this.faultList()
  },


  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    var that = this;
	var filterValue = that.data.filterValue;
    that.setData({
    	FList:[],
    	page:0,
    	totalPage:0,
		filterValue:filterValue
    });
    that.faultList();
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {	
    var that=this;
    var page = that.data.page + 1; 
    if(page<=that.data.totalPage-1){	
    	that.setData({
    		page: page, 
			filterValue:that.data.filterValue
    	})					
    	that.faultList();
    }else{
    	that.setData({
    		loaded:true,
    		loading:false,
			filterValue:that.data.filterValue
    	})
    }
	
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})